﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Logistics.Model;
using Logistics.Pageing;
using Microsoft.EntityFrameworkCore;

using Volo.Abp.Application.Services;

namespace Logistics.PersonnelMatters { 

public class PersonnelMattersAppService : ApplicationService, IPersonnelMattersAppService
{
    private readonly IPersonnelMattersRepository _personnelMattersRepository;

        public PersonnelMattersAppService(IPersonnelMattersRepository personnelMattersRepository)
        {
            _personnelMattersRepository = personnelMattersRepository;
        }


        /// <summary>
        ///     获取部门集合
        /// </summary>
        /// <returns></returns>
        public async Task<List<Deptinfo>> GetDeptinfoList()
        {
            var dep = await _personnelMattersRepository.GetDeptinfoList();
            return dep;
        }


        /// <summary>
        ///     获取职位集合
        /// </summary>
        /// <returns></returns>
        public async Task<List<PositionInfo>> GetPositionInfoList(int id)
        {
            var posi = await _personnelMattersRepository.GetPositionInfoList(id);
            return posi;
        }

        #region 人事面板

        /// <summary>
        ///     离职人数
        /// </summary>
        /// <returns></returns>
        public async Task<int> GetDimissionCount()
        {
            var count = await _personnelMattersRepository.DimissionCount();
            return count;
        }

        /// <summary>
        ///     总人数
        /// </summary>
        /// <returns></returns>
        public async Task<int> GetHeadcount()
        {
            var count = await _personnelMattersRepository.Headcount();
            return count;
        }

        /// <summary>
        ///     入职人数
        /// </summary>
        /// <returns></returns>
        public async Task<int> GetInductionCount()
        {
            var count = await _personnelMattersRepository.InductionCount();
            return count;
        }

        /// <summary>
        ///     获取员工年龄比
        /// </summary>
        /// <returns></returns>
        public async Task<List<AgeRatio>> GetEmployeeAgeRatio()
        {
            var ageRatio = await _personnelMattersRepository.GetEmployeeAgeRatio();
            return ageRatio;
        }

        /// <summary>
        ///     获取员工年龄比
        /// </summary>
        /// <returns></returns>
        public async Task<List<AgeRatio>> GetSeniorityRatio()
        {
            var ageRatio = await _personnelMattersRepository.GetSeniorityRatio();
            return ageRatio;
        }

        /// <summary>
        ///     获取部门人数
        /// </summary>
        /// <returns></returns>
        public async Task<List<NumberOfDepartments>> GetDepartment()
        {
            var dep = await _personnelMattersRepository.GetDepartment();
            return dep;
        }

        /// <summary>
        ///     获取离职人数
        /// </summary>
        /// <returns></returns>
        public async Task<List<AgeRatio>> GetNumberOfSeparations()
        {
            var age = await _personnelMattersRepository.GetNumberOfSeparations();
            return age;
        }

        #endregion

        #region 人事登记

        /// <summary>
        ///     新增员工
        /// </summary>
        /// <param name="basic"></param>
        /// <returns></returns>
        public async Task<int> AddBasic(BasicDto basic)
        {
            var bas = ObjectMapper.Map<BasicDto, Basic>(basic);
            var i = await _personnelMattersRepository.AddBasic(bas);
            return i;
        }


        /// <summary>
        ///     删除员工数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> DelBasicById(string id)
        {
            var i = await _personnelMattersRepository.DelBasicById(id);
            return i;
        }

        /// <summary>
        ///     根据编号获取员工数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<Basic> GetBasicById(int id)
        {
            var bas = await _personnelMattersRepository.GetBasicById(id);
            return bas;
        }

        /// <summary>
        ///     获取员工数据
        /// </summary>
        /// <param name="name">通过员工名称进行模糊查询</param>
        /// <param name="phone">通过员工手机号进行模糊查询</param>
        /// <param name="departmentId">通过部门进行查询</param>
        /// <param name="category">通过类别进行查询</param>
        /// <param name="positionId">通过职位进行查询</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">页容量</param>
        /// <returns></returns>
        public async Task<BasucPageIng> GetBasicList(string name, string phone, int departmentId, string category,
            int positionId, int pageIndex, int pageSize)
        {
            var basiList = await _personnelMattersRepository.GetBasicList(name, phone, departmentId, category,
                positionId, pageIndex, pageSize);
            return basiList;
        }

        /// <summary>
        ///     修改员工数据
        /// </summary>
        /// <param name="basic"></param>
        /// <returns></returns>
        public async Task<int> PutBasic(Basic basic)
        {
            var i = await _personnelMattersRepository.PutBasic(basic);
            return i;
        }

        #endregion

        #region 入职

        /// <summary>
        ///     新增入职记录
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        public async Task<int> AddEntryData(Entry entry)
        {
            var i = await _personnelMattersRepository.AddEntryData(entry);
            return i;
        }

        /// <summary>
        ///     通过部门编号获取该部门的员工数据
        /// </summary>
        /// <param name="depId"></param>
        /// <returns></returns>
        public async Task<List<Basic>> GetBasicByDepId(int depId)
        {
            var basic = await _personnelMattersRepository.GetBasicByDepId(depId);
            return basic;
        }

        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="name"></param>
        /// <param name="depId"></param>
        /// <param name="postId"></param>
        /// <param name="state"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<EntryPageIng> GetEntryList(string name, int depId, int postId, int state, int pageIndex,
            int pageSize)
        {
            var basiList = await _personnelMattersRepository.GetEntryList(name, depId, postId, state, pageIndex, pageSize);
            return basiList;
        }

        /// <summary>
        /// 删除入职数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> DelEntryById(string id)
        {
            var iids = await _personnelMattersRepository.DelEntryById(id);
            return iids;
        }

        /// <summary>
        /// 通过编号获取入职数据
        /// </summary>
        /// <param name="id"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public async Task<Entry> GetEntryData(int id, int state)
        {
            var obj = await _personnelMattersRepository.GetEntryData(id, state);
            return obj;
        }

        /// <summary>
        /// 修改入职数据
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        public async Task<int> PutEntry(Entry entry)
        {
            var i = await _personnelMattersRepository.PutEntry(entry);
            return i;
        }

        /// <summary>
        /// 提交入职申请
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> SubmitEntry(int id)
        {
            var i = await _personnelMattersRepository.SubmitEntry(id);
            return i;
        }

        #endregion

        #region 转正

        /// <summary>
        ///     新增转正记录
        /// </summary>
        /// <param name="become"></param>
        /// <returns></returns>
        public async Task<int> AddBecomeData(Become become)
        {
            var i = await _personnelMattersRepository.AddBecomeData(become);
            return i;
        }

        /// <summary>
        ///     通过部门编号获取该部门的员工数据
        /// </summary>
        /// <param name="depId"></param>
        /// <returns></returns>
        public async Task<List<Become>> GetBecomeByDepId(int depId)
        {
            var basic = await _personnelMattersRepository.GetBecomeByDepId(depId);
            return basic;
        }

        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="name"></param>
        /// <param name="depId"></param>
        /// <param name="postId"></param>
        /// <param name="state"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<BecomePageIng> GetBecomeList(string name, int depId, int postId, int state, int pageIndex,
            int pageSize)
        {
            var basiList = await _personnelMattersRepository.GetBecomeList(name, depId, postId, state, pageIndex, pageSize);
            return basiList;
        }

        /// <summary>
        /// 删除转正数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> DelBecomeById(string id)
        {
            var iids = await _personnelMattersRepository.DelBecomeById(id);
            return iids;
        }

        /// <summary>
        /// 通过编号获取转正数据
        /// </summary>
        /// <param name="id"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public async Task<Become> GetBecomeData(int id, int state)
        {
            var obj = await _personnelMattersRepository.GetBecomeData(id, state);
            return obj;
        }

        /// <summary>
        /// 修改转正数据
        /// </summary>
        /// <param name="become"></param>
        /// <returns></returns>
        public async Task<int> PutBecome(Become become)
        {
            var i = await _personnelMattersRepository.PutBecome(become);
            return i;
        }

        /// <summary>
        /// 提交转正申请
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> SubmitBecome(int id)
        {
            var i = await _personnelMattersRepository.SubmitBecome(id);
            return i;
        }

        #endregion

        #region 离职

        /// <summary>
        ///     新增离职记录
        /// </summary>
        /// <param name="dimission"></param>
        /// <returns></returns>
        public async Task<int> AddDimissionData(Dimission dimission)
        {
            var i = await _personnelMattersRepository.AddDimissionData(dimission);
            return i;
        }

        /// <summary>
        ///     通过部门编号获取该部门的员工数据
        /// </summary>
        /// <param name="depId"></param>
        /// <returns></returns>
        public async Task<List<Dimission>> GetDimissionByDepId(int depId)
        {
            var basic = await _personnelMattersRepository.GetDimissionByDepId(depId);
            return basic;
        }

        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="name"></param>
        /// <param name="depId"></param>
        /// <param name="postId"></param>
        /// <param name="state"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<DimissionPageIng> GetDimissionList(string name, int depId, int postId, int state, int pageIndex,
            int pageSize)
        {
            var basiList = await _personnelMattersRepository.GetDimissionList(name, depId, postId, state, pageIndex, pageSize);
            return basiList;
        }

        /// <summary>
        /// 删除离职数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> DelDimissionById(string id)
        {
            var iids = await _personnelMattersRepository.DelDimissionById(id);
            return iids;
        }

        /// <summary>
        /// 通过编号获取离职数据
        /// </summary>
        /// <param name="id"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public async Task<Dimission> GetDimissionData(int id, int state)
        {
            var obj = await _personnelMattersRepository.GetDimissionData(id, state);
            return obj;
        }

        /// <summary>
        /// 修改离职数据
        /// </summary>
        /// <param name="dimission"></param>
        /// <returns></returns>
        public async Task<int> PutDimission(Dimission dimission)
        {
            var i = await _personnelMattersRepository.PutDimission(dimission);
            return i;
        }

    /// <summary>
    /// 提交离职申请
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    /// 
    public async Task<int> SubmitDimission(int id)
    {
        var i = await _personnelMattersRepository.SubmitDimission(id);
        return i;
    }

        #endregion
    }
    }              